package com.example.qixin0314.bean;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.qixin0314.Activity.CompanyActivity;
import com.example.qixin0314.R;

import java.util.List;

public class companyAdapter extends RecyclerView.Adapter<companyAdapter.companyHolder> {
    private List<companyModel>companyData;

    public void setCompanyData(List<companyModel> companyData) {
        this.companyData = companyData;
    }

    private Context context;

    public companyAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public companyHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new companyHolder(LayoutInflater.from(context).inflate(R.layout.company_item_view,null));
    }

    @Override
    public void onBindViewHolder(@NonNull  companyAdapter.companyHolder holder, int position) {
        if (!companyData.get(position).getIconUri().isEmpty()) {
            //with()方法创建对象
            Glide.with(context).load(companyData.get(position).getIconUri()).into(holder.list_icon);
        }
        else {
            holder.list_icon.setImageResource(R.drawable.shouye);
        }
        holder.list_theme.setText(companyData.get(position).getListTheme());
        holder.list_company.setText(companyData.get(position).getCompanyName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, CompanyActivity.class);
                intent.putExtra("uri","http://m.qxswt.com/company/"+companyData.get(position).getId());
                intent.putExtra("name",companyData.get(position).getCompanyName());
                intent.putExtra("puri",companyData.get(position).getIconUri());
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return null != companyData ? companyData.size() : 0;
    }

    class companyHolder extends RecyclerView.ViewHolder{
        ImageView list_icon;
        TextView list_theme;
        TextView list_company;

        public companyHolder(@NonNull View itemView) {
            super(itemView);
            list_icon=itemView.findViewById(R.id.list_icon);
            list_theme=itemView.findViewById(R.id.list_theme);
            list_company=itemView.findViewById(R.id.list_company);
        }
    }
}
